﻿namespace WMS6.Services
{
    using System;
    using System.Collections.Generic;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using WMS6.BLL;
    using WMS6.Common;
    using WMS6.DataEntity;

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall), AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
    public class LoginService : ILoginService
    {
        public string CheckIsVendorExist(string userID, string type, PubParasInfo pubParasInfo)
        {
            string result = "N";
            try
            {
                if (BaseInfoFactory.CreateInstance(type, pubParasInfo).GetInfoByID(userID) != null)
                {
                    result = "Y";
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "BaseInfoService异常");
            }
            return result;
        }

        public List<GlobalSettingInfo> GetALLGlobalSetting()
        {
            GlobalSettingBLL globalSettingBLL = new GlobalSettingBLL();
            try
            {
                return globalSettingBLL.GetALLGlobalSetting();
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return null;
        }

        public PreferenceProfileInfo GetPreferenceProfileByUserID(string userID)
        {
            try
            {
                UserPreferenceBLL userPreference = new UserPreferenceBLL();
                return userPreference.GetPreferenceProfileByUserID(userID);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "BaseInfoService异常");
            }
            return null;
        }

        public UserMstInfo GetUserInfoByID(string userID)
        {
            try
            {
                return (BaseInfoFactory.CreateInstance("USER_MST", null).GetInfoByID(userID) as UserMstInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "BaseInfoService异常");
            }
            return null;
        }

        public void InsertSysLoginLogInfo(SysLoginLogInfo sysLoginLogInfo)
        {
            try
            {
                new SysLoginLogBLL().InsertSysLoginLogInfo(sysLoginLogInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "BaseInfoService异常");
            }
        }

        public string InsertUserPreference(PreferenceProfileInfo preferencePrifile)
        {
            try
            {
                UserPreferenceBLL userPreference = new UserPreferenceBLL();
                return userPreference.InsertUserPreference(preferencePrifile);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "BaseInfoService异常");
            }
            return null;
        }

        public string UpdateGlobalSetting(GlobalSettingInfo globalSettingInfo)
        {
            GlobalSettingBLL globalSettingBLL = new GlobalSettingBLL();
            try
            {
                return globalSettingBLL.UpdateGlobalSetting(globalSettingInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return null;
        }
    }
}

